Add alias and forget commands for user-defined package aliases#23
Add alias and forget commands for user-defined package aliases#23TitasGailius wants to merge 9 commits into
Conversation
|
|
||
| $json = json_decode((string) file_get_contents($file), true); | ||
|
|
||
| return new self(array_map( |
There was a problem hiding this comment.
A malformed ~/.cpx/aliases.json (invalid JSON, non-array root, or one bad value) throws and breaks every cpx command, including cpx forget, which is how a user would fix it. Let's mirror the is_array() guard already used in Application::resolveVersion(), bail to an empty state otherwise, and skip individual unparseable entries.
There was a problem hiding this comment.
@WendellAdriel Since aliases.json only gets malformed by hand-editing, bailing to an empty state worries me: the user never really sees the error, and because save() rewrites the whole file, the next alias/forget overwrites their file with the empty state, turning a fixable typo into real data loss.
So I'm wondering, isn't failing loudly with an explicit error more useful and safe approach?
|
This looks like it covers the primary use case when a binary matches the package/vendor name clearly, do you think there's appetite for another question/parameter for packages that have multiple binaries when it isn't entirely clear? For example:
|
Creating aliases
Added
cpx alias [package] [name]to let users create their own shortcut for a package (e.g.cpx alias laravel/pint pint), prompting interactively via Laravel Prompts for whichever argument is omitted.Listing aliases
cpx aliasesnow also lists user-defined aliases under a "Your aliases" section alongside the built-in ones.Deleting aliases
Added
cpx forget [name]to remove a saved alias, with a select prompt listing existing aliases when the name is omitted.Other
~/.cpx/aliases.jsonand take priority over the built-in aliases at dispatch time, so a user can override e.g. pint to point elsewhere.